#include "Stock.h"

Stock::Stock( void )
{
}

Stock::Stock( const wchar_t* FileName )
: _stock_worker( FileName ), _indexer( &_stock_worker )
{
}

Stock::Stock( const wstring& FileName )
: _stock_worker( FileName ), _indexer( &_stock_worker )
{
}

Stock::~Stock( void )
{
	close();
}

void Stock::assign( const wchar_t* FileName )
{
	_stock_worker.assign( FileName );
	_indexer.assign( &_stock_worker );
}

void Stock::assign( const wstring& FileName )
{
	assign( FileName.c_str() );
}

Record Stock::read( int id )
{
	int offset = _indexer.get_offset( id );
	return _stock_worker.read_record( offset );
}

void Stock::write( const Record& rec )
{
	int offset = _stock_worker.write_record( rec );
	_indexer.add( rec.id, offset );
}

void Stock::clear( void )
{
	_stock_worker.clear();
	_indexer.clear();
}

void Stock::close( void )
{
	_stock_worker.close();
	_indexer.save_index();
}